package com.whut.transportation.overweight;

import java.util.HashMap;

import com.whut.transportation.R;
import com.whut.transportation.entity.DealedWeighingInfo;
import com.whut.transportation.entity.OverWeightInfo;
import com.whut.transportation.entity.TaskInfo;
import com.whut.transportation.entity.TransInfo;
import com.whut.transportation.entity.ShowDealedWeighInfo;
import com.whut.transportation.network.HttpManager;
import com.whut.transportation.network.HttpRequestVo;
import com.whut.transportation.parser.JSONParser;
import com.whut.transportation.ui.BaseActivity;
import com.whut.transportation.ui.BaseActivity.DataCallback;
import com.whut.transportation.utils.Constant;

import android.R.string;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.view.View;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;

public class OWCompletedDetailActivity extends BaseActivity{
	
	private LinearLayout owcompleted;
	private TextView shunNumber;
	private TextView trainNumber;
	private TextView train;
	private TextView owTime;
	private TextView zaizhong;
	private TextView zizhong;
	private TextView chaoqian;
	private TextView pianzai;
	private TextView pianzhong;
	private TextView isWeigh;
	
	private View activity_owcompleted_detail_timefinish;
	private LinearLayout owcompleted_timefinish;
	private TextView timeFinish;
	
	private View acitvity_owcompleted_detail_description;
	private LinearLayout owcompleted_description;
	private TextView description;
	
	
	
	private OverWeightInfo overWeightInfo;
	private ShowDealedWeighInfo showDealedWeighInfo;

	
	private SharedPreferences preferences;

	@Override
	protected void findViewById() {
		// TODO Auto-generated method stub
		owcompleted = (LinearLayout) findViewById(R.id.owcompleted);
		shunNumber = (TextView) findViewById(R.id.shunNumber);
		trainNumber = (TextView) findViewById(R.id.trainNumber);
		train = (TextView) findViewById(R.id.train);
		owTime = (TextView) findViewById(R.id.owTime);
		zaizhong = (TextView) findViewById(R.id.zaizhong);
		zizhong = (TextView) findViewById(R.id.zizhong);
		chaoqian = (TextView) findViewById(R.id.chaoqian);
		pianzai = (TextView) findViewById(R.id.pianzai);
		pianzhong = (TextView) findViewById(R.id.pianzhong);
		isWeigh = (TextView) findViewById(R.id.isWeigh);
		
		owcompleted_timefinish = (LinearLayout) activity_owcompleted_detail_timefinish.findViewById(R.id.owcompleted_timefinish);
		timeFinish = (TextView) activity_owcompleted_detail_timefinish.findViewById(R.id.timeFinish);
		
		owcompleted_description = (LinearLayout) acitvity_owcompleted_detail_description.findViewById(R.id.owcompleted_description);
		description = (TextView) acitvity_owcompleted_detail_description.findViewById(R.id.description);
	}

	@Override
	protected void afterFindViewId() {
		// TODO Auto-generated method stub
		shunNumber.setText(shunNumber.getText()+overWeightInfo.getShunNumber());
		trainNumber.setText(trainNumber.getText()+overWeightInfo.getTrainNumber());
		train.setText(train.getText()+overWeightInfo.getTrain());
		owTime.setText(owTime.getText()+overWeightInfo.getOwTime());
		zaizhong.setText(zaizhong.getText()+String.valueOf(overWeightInfo.getZaizhong()));
		zizhong.setText(zizhong.getText()+String.valueOf(overWeightInfo.getZizhong()));
		chaoqian.setText(chaoqian.getText()+String.valueOf(overWeightInfo.getChaoqian()));
		pianzai.setText(pianzai.getText()+String.valueOf(overWeightInfo.getPianzai()));
		pianzhong.setText(pianzhong.getText()+String.valueOf(overWeightInfo.getPianzhong()));
		
		
		
	}

	@Override
	protected void loadViewLayout() {
		// TODO Auto-generated method stub
		setContentView(R.layout.activity_owcompleted_detail);
		activity_owcompleted_detail_timefinish=View.inflate(mContext, R.layout.activity_owcompleted_detail_timefinish, null);
		acitvity_owcompleted_detail_description = View.inflate(mContext, R.layout.activity_owcompleted_detail_description, null);
		Intent intent = getIntent();
		overWeightInfo = (OverWeightInfo) intent.getSerializableExtra("overWeightInfo");
		preferences=getSharedPreferences("userId", Context.MODE_PRIVATE);
		setTitleBarView(true, overWeightInfo.getTrainNumber()+"过衡处理情况", -1, true);
	}

	@Override
	protected void processLogic() {
		// 查询已经完成的超重处理信息
		HttpRequestVo vo = new HttpRequestVo();
		vo.requestUrl = Constant.FIND_WEIGHDEALING_INFO;
		vo.context = mContext;
		
		HashMap<String, String> req = new HashMap<String, String>();
		req.put("weighDealingInfo.serialId", overWeightInfo.getShunNumber());
		vo.requestDataMap = req;
		vo.parser = new JSONParser(ShowDealedWeighInfo.class);
		getDataFromServer(HttpManager.POST_MOTHOD, vo, 
				new DataCallback<HashMap<String, Object>>() {
					@Override
					public void onStart() {
					}
					@Override
					public void onFailed() {
						showNetErrorDialog();
					}
					@Override
					public void processData(
							HashMap<String, Object> paramObject,
							boolean paramBoolean) {
						//将查询出来的卸车信息放入到界面中
						showDealedWeighInfo = (ShowDealedWeighInfo) paramObject.get("result");
						int message = showDealedWeighInfo.getMessage();
						//String dealFlag = showDealedWeighInfo.getDealFlag().trim();
						switch (message) {
						case 0:
							isWeigh.setText(isWeigh.getText()+"未超重");
							owcompleted.removeView(activity_owcompleted_detail_timefinish);
							owcompleted.removeView(acitvity_owcompleted_detail_description);
							break;
						case 1:
							isWeigh.setText(isWeigh.getText()+"超重");
							owcompleted.addView(activity_owcompleted_detail_timefinish);
							timeFinish.setText(timeFinish.getText()+showDealedWeighInfo.getDealtime().trim());
							//if (dealFlag.equals("0")) {
								owcompleted.addView(acitvity_owcompleted_detail_description);
								description.setText(description.getText()+showDealedWeighInfo.getDescription().trim());
							//}
							break;
						default:
							break;
						}

					}
					@Override
					public void onFinish() {
						// TODO Auto-generated method stub
						closeProgressDialog();
					}

				});
	}

	@Override
	protected void setListener() {
		// TODO Auto-generated method stub
		
	}

	@Override
	protected void getDataAgain() {
		// TODO Auto-generated method stub
		
	}
	
}
